package conv

import (
	"strconv"
)

func ToInt64(obj interface{}, defaultValue int64) int64 {
	switch obj.(type) {
	case string:
		ret, err := strconv.ParseInt(obj.(string), 10, 64)
		if err != nil{
			return defaultValue
		}
		return ret
	case int:
		return int64(obj.(int))
	case int64:
		return obj.(int64)
	case float32:
		return int64(obj.(float32))
	case float64:
		return int64(obj.(float64))
	default:
		return defaultValue
	}
}